<template>
  <div>
   <home-header ></home-header>
   <home-swiper :list = "swiperList"></home-swiper>
   <Icons :iconList = "iconList"></Icons>
  <HomeRecommend :recommendList = "recommendList"></HomeRecommend>
  <HomeWeekend :weekendList = "weekendList"></HomeWeekend>
  </div>
</template>

<script>
import HomeHeader from './components/Header'
import HomeSwiper from './components/Swiper'
import Icons from './components/Icons'
import HomeRecommend from './components/Recommend'
import HomeWeekend from './components/Weekend'
import Axios from 'axios'
import {mapState} from 'vuex'
export default {
  name: 'Home',
  components: {
    HomeHeader,
    HomeSwiper,
    Icons,
    HomeRecommend,
    HomeWeekend
  },
  data () {
    return {
      // city: '',
      lastCity:'',
      swiperList: [],
      iconList: [],
      recommendList: [],
      weekendList: [],
    }

  },
  computed:{
    ...mapState(['city'])
  },
  methods:{
    getHomeInfo: function(){
      Axios.get('/api/index.json?city='+this.city)
        .then(this.getHomeInfos)
    },
    getHomeInfos: function(res){
      res = res.data
      if(res.ret && res.data){
        const data = res.data
        // this.city = data.city
        this.swiperList = data.swiperList
        this.iconList = data.iconList
        this.recommendList = data.recommendList
        this.weekendList = data.weekendList

      }
      console.log(res)
    }
  },
  mounted () {//首次进入
    this.lastCity = this.city
    this.getHomeInfo()
  },
  activated(){//页面每次重新显示
    if(this.lastCity !== this.city){
      this.lastCity = this.city
      this.getHomeInfo();
    }
    
  }
}
</script>

<style lang="stylus" scoped>

</style>
